package com.cyf.db.bean;

import com.cyf.util.DateUtil;

import java.util.Date;

/**
 * 车位预约信息
 * Created by cage on 2017/4/7.
 */
public class BookingInfo {


    /** 订单已预约 **/
    public static final int BOOKINGSTATUS_BOOKED = 1;
    /** 订单已完成 **/
    public static final int BOOKINGSTATUS_FINISHED = 2;
    /** 订单已失效（超时和取消预约） **/
    public static final int BOOKINGSTATUS_FAILURE = 3;

    /** 预约信息已经发送车场，取消预约，更新发送状态为2 **/
    public static final int SEND_CANCELBOOKING = 2;
    /** 预约信息已经发送车场，地锁升降通知，更新发送状态为3 **/
    public static final int SEND_UPDATE_PARKINGLOCK = 3;

    private Integer id;
    private Integer appUserId;      // app用户id
    private Integer parkingId;      // 车场id
    private Integer parkingLockId;  // 地锁id
    private Date createdTime;       // 预约时间
    private Date endTime;           // 车位预约完成时间
    private Integer bookingStatus;  // 订单状态
    private Integer sendToParking;  // 是否已经发送到车场 1发送 0未发送 2发送了，但是取消预约了 3发送了，但是地锁id或地锁升降状态更新了

    private Integer feeType;       // 预约类型 1-半个小时
    private Integer fee;           // 费用

    // 以下是查询用到的字段
    private String parkingLockName;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getAppUserId() {
        return appUserId;
    }

    public void setAppUserId(Integer appUserId) {
        this.appUserId = appUserId;
    }

    public Integer getParkingId() {
        return parkingId;
    }

    public void setParkingId(Integer parkingId) {
        this.parkingId = parkingId;
    }

    public Integer getParkingLockId() {
        return parkingLockId;
    }

    public void setParkingLockId(Integer parkingLockId) {
        this.parkingLockId = parkingLockId;
    }

    public Date getCreatedTime() {
        return createdTime;
    }

    public void setCreatedTime(Date createdTime) {
        this.createdTime = createdTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public Integer getBookingStatus() {
        return bookingStatus;
    }

    public void setBookingStatus(Integer bookingStatus) {
        this.bookingStatus = bookingStatus;
    }

    public Integer getSendToParking() {
        return sendToParking;
    }

    public void setSendToParking(Integer sendToParking) {
        this.sendToParking = sendToParking;
    }

    public Integer getFeeType() {
        return feeType;
    }

    public void setFeeType(Integer feeType) {
        this.feeType = feeType;
    }

    public Integer getFee() {
        return fee;
    }

    public void setFee(Integer fee) {
        this.fee = fee;
    }

    public String getParkingLockName() {
        return parkingLockName;
    }

    public void setParkingLockName(String parkingLockName) {
        this.parkingLockName = parkingLockName;
    }

    /**
     * 计算EB支持的预约截止时间
     *
     * @param bookingTime   预约时间
     * @param freeHours     预约一次最多支持的时间(秒)
     * @return  Date
     */
    public Date caculateEndTimeWithOnce(Date bookingTime, Integer freeHours) {
        return DateUtil.getDateAfterSeconds(bookingTime, freeHours);
    }

    /**
     * 计算EB支持的预约截止时间
     * @param bookingTime   预约时间
     * @param ebBalance     EB余额
     * @param freeAmount    半小时收费金额
     * @return  Date
     */
    public Date caculateEndTimeWithHours(Date bookingTime, Integer ebBalance, Integer freeAmount) {
        int count = ebBalance / freeAmount;
        if (ebBalance % freeAmount > 0) {
            count++;
        }
        return DateUtil.getDateAfterSeconds(bookingTime, count * 30 * 60);
    }
}
